/*
 * @描述信息: 测试mock
 * @Author:  zls
 */
import Mock from 'mockjs'
const Random = Mock.Random

export default [
  {
    url: '/api/textMock1',
    type: 'get',
    flag: true,
    response: () => {
      return {
        name: 'zls',
        age: 18
      }
    }
  },
  {
    url: '/api/textMock2',
    type: 'post',
    flag: true,
    response: (params: any) => {
      const list = []
      for (let i = 0; i < Random.integer(46, 46); i++) {
        list.push({
          'id|+1': 1,
          'type|1': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
          deviceId: Random.id(),
          deviceName: Random.ctitle(),
          name: Random.name(),
          location: Random.province(),
          controlType: Random.id(),
          controlTypeName: Random.cparagraph(),
          command: Random.cparagraph(),
          controller: Random.cname(),
          createTime: Random.datetime()
        })
      }
      const obj = params.body
      const [curPage, pageSize, totalNum] = [obj.page, obj.pageSize, list.length]
      const totalPage = totalNum > 0 ? Math.ceil(totalNum / pageSize) : 0
      const data = list.slice((curPage - 1) * pageSize, curPage * pageSize)
      return { curPage, pageSize, totalNum: list.length, totalPage, data }
    }
  }
]
